-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support vectorized interpolation with more scipy interpolators #9526
Conversation
hollymandel
commented
Sep 20, 2024
•
edited
Loading
edited
- Closes Cannot use documented interp() methods due to "vectorizeable_only" check and kwargs name clash #9049
- Adds support for vectorized (broadcast) 1d interpolation using SciPy interpolants, including "akima" and "makima"
- Does not add support for deprecated SplineInterpolator (but upholds preexisting functionality). I wanted to add a deprecation warning but this caused tests to fail so I left it commented.
- Akima and makima cases added to test_interp.py::test_interpolate_vectorize
Something has gone kinda wrong with git here! Maybe try squashing to a single commit? |
519d2c6
to
09a9e73
Compare
yes, done, thanks! |
Nice, thanks! (I don't know this code well so will defer to others on the review, hope that's OK...) |
Sounds good! I actually wanted it to be a "draft PR" as I'm still double-checking it, though perhaps submitting it this way is confusing on the maintainers' end and I should rescind until it's ready. |
we're actually happy to have PRs developed like this, it allows us to guide people more easily in case there's any issues. This includes advising in case the direction is seriously wrong (which I don't think it is in this case, but I also don't know this area too well) Just tell us when you think this is ready or if you need any help. |
9ec3e07
to
9c33edf
Compare
@@ -614,9 +623,6 @@ def interp(var, indexes_coords, method: InterpOptions, **kwargs): | |||
if not indexes_coords: | |||
return var.copy() | |||
|
|||
# default behavior |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice cleanup!
xarray/tests/test_interp.py
Outdated
if not has_scipy: | ||
pytest.skip("scipy is not installed.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not has_scipy: | |
pytest.skip("scipy is not installed.") |
driveby cleanup. The requires_scipy
decorator will skip the test if scipy isn't available. Import it from xarray.tests
if it's not present.
xarray/core/missing.py
Outdated
@@ -755,8 +761,9 @@ def interp_func(var, x, new_x, method: InterpOptions, kwargs): | |||
|
|||
def _interp1d(var, x, new_x, func, kwargs): | |||
# x, new_x are tuples of size 1. | |||
x, new_x = x[0], new_x[0] | |||
rslt = func(x, var, assume_sorted=True, **kwargs)(np.ravel(new_x)) | |||
x, new_x = x[0].data, new_x[0].data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The addition of
.data
is significant. Where did the types change? We seem to have moved fromnp.ndarray
toVariable
? - Is there a reason you got rid of
assume_sorted=True
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
This doesn't seem to have been necessary, changing back
-
The interpolators I have added (
Scipy.Interpolate.Akima1DInterpolator
, etc...) require sorted axes but don't takeassume_sorted
as an argument. OnlyScipy.Interpolate.Interp1d
takes this argument. Since we are always calling it withTrue
, I'm just letting the default for ScipyInterpolator init impose this.
There is maybe a philosophical conflict here and in previous comments about kwarg handling for the different interpolators. The preexisting script (missing.py
) has special classes (NumpyInterpolator
, ScipyInterpolator
...) which basically just do this handling. I didn't add any new classes for the new interpolators and rather tried to do everything with kwargs determined by _get_interpolator
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re (1): If you're comfortable with typing, some type hints would go a long way towards improving this module.
Re (2): sounds good
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(1) Yeah can do! Prefer a separate commit though (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we squash merge so it doesn't matter :) unless you meant separate PR, in which case that would be fine too.
Nice progress! I pushed a commit that should handle the min scipy version failure with Please add a note to
Yes, we error on unexpected warnings. To add this, catch the warning using with pytest.warns(DeprecationWarning):
...
It also let us handle the annoying pieces like min scipy versions ;). We have established patterns to handle such things, but its hard for a new contributor to find them at first glance |
425874c
to
76defd1
Compare
76defd1
to
623be9f
Compare
(fyi we squash on merge, so you needn't squash every change) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work! Thanks for taking this on, we've needed someone to do this for a while now :)
One last request, please add a note to whats-new.rst
Thanks @hollymandel ! |